/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server;

import java.util.Comparator;

/**
 *
 * @author Czarek
 */
public class SpecificationComparator<T> implements Comparator<T> {
    
    private final Comparator<T> mainComparator;
    private final Comparator<T> specification;

    public SpecificationComparator(Comparator<T> mainComparator, Comparator<T> specification) {
        this.mainComparator = mainComparator;
        this.specification = specification;
    }  
    

    @Override
    public int compare(T o1, T o2) {
        final int diff = mainComparator.compare(o1, o2);
        if(diff==0){
            return specification.compare(o1, o2);
        }
        return diff;
    }
    
}
